<template>
    <currentTime @sendTime="getTime" />
    <div class="background-image">
        <div class="top-bar">
            <div class="auth-links">
                <router-link to="/auth" class="login">登录/注册</router-link>
            </div>
        </div>
        <div class="container">
            <!-- <div class="ball" :style="{ left: offsetX + 'px', top: offsetY + 'px' }"></div> -->
            <div class="sideBar">
                <router-link :to="item.path" v-for="item in mainList" :key="item.name"
                    :class="{ active: $route.path === item.path }">
                    <span>{{ item.name }}</span>
                </router-link>
            </div>
            <div class="main">
                <div class="router-container">
                    <router-view v-slot="{ Component }">
                        <!-- 将过渡容器移到外层 -->
                        <div class="transition-wrapper">
                            <transition :name="trans" mode="out-in">
                                <component :is="Component" />
                            </transition>
                        </div>
                    </router-view>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import currentTime from '@/components/currentTime.vue';
import { transform } from 'typescript';
import { useRouter } from 'vue-router';

const sideBar = ref(null);
const main = ref(null);
// let offsetX = ref(0);
// let offsetY = ref(0);
const time = ref();
const trans = ref();
let router = useRouter();


router.beforeEach((to, from, next) => {
    if (to.meta.index > from.meta.index) {
        trans.value = 'slide-up';
    } else if (to.meta.index < from.meta.index) {
        trans.value = 'slide-down';
    } else {
        trans.value = '';
    }
    next();
});

// const move = (event: MouseEvent) => {
//     offsetX.value = event.screenX - 10
//     offsetY.value = event.screenY - 10
// }

function getTime(e: String) {
    time.value = e;
    // console.log(time.value);
}

const mainList = [
    { name: '首页', path: '/welcome' },
    { name: '个人画廊', path: '/about' },
    { name: '教育背景', path: '/sch' },
]

// 1、性能优化（图片懒加载）
// 引用第三方插件：vue-lazy

// 2、数据仓库 （Vuex）
</script>
<style scoped>
html,
body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    /* 禁用全局滚动 */
}

.background-image {
    width: 100%;
    height: 100%;
    padding-top: 50px;
    position: relative;
    background-size: cover;
    background-position: center;
    background-image: url('..\assets\BGI-III.png');
    overflow: hidden;
}

.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 50px;
    background: rgba(59, 59, 61, 0.6);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid rgba(190, 198, 199, 0.2);
    z-index: 1000;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 0 30px;
}

.auth-links {
    display: flex;
    align-items: center;
    gap: 20px;

    .login {
        color: rgba(255, 255, 255, 0.9);
        font-size: 16px;
        font-weight: 300;
        transition: all 0.3s ease;
        text-decoration: none;
        position: relative;
        top: 0px;

        &:hover {
            color: #6DD5FA;
            transform: translateY(-1px);
        }

        &::after {
            content: '';
            position: absolute;
            bottom: -2px;
            left: 0;
            width: 0;
            height: 1px;
            background: #6DD5FA;
            transition: width 0.3s ease;
        }

        &:hover::after {
            width: 100%;
        }
    }

    .divider {
        color: rgba(190, 198, 199, 0.3);
        font-weight: 200;
    }
}

.container {
    display: flex;
    background: transparent;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    height: calc(100vh - 50px);
    /* 总视口高度减去顶部栏高度 */
    overflow: hidden;
}

.time {
    position: absolute;
    bottom: 20px;
    right: 20px;
    font-size: 15px;
    color: rgb(255, 255, 255);
    font-weight: lighter;
}

.sideBar {
    width: 20%;
    height: 91.5%;
    background: rgba(59, 59, 61, 0.6);
    backdrop-filter: blur(8px);
    position: fixed;
    top: 5%;
    left: 0;
    z-index: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;

    ul {
        list-style: none;
        margin: 0;
        padding: 0;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;

        li {
            font-size: 40px;
            color: white;
            margin-top: 40px;
            transition: all 0.3s ease;
            text-shadow: 1px 1px 2px black;
            font-weight: bold;
            cursor: pointer;
        }
    }

    a {
        color: rgba(255, 255, 255, 0.9);
        font-size: 30px;
        /* 适当放大字体 */
        font-weight: 300;
        margin: 20px 0;
        /* 增加间距 */
        padding: 8px 0;
        position: relative;
        transition: all 0.3s ease;
        text-decoration: none;
        text-shadow: none;
        /* 移除文字阴影 */
        display: flex;
        align-items: center;
    }

    a:hover {
        color: #6DD5FA;
        transform: translateX(10px);
        /* 添加文字悬浮偏移 */
    }

    a::after {
        /* 画线 */
        content: '';
        position: absolute;
        bottom: -2px;
        left: 0;
        width: 0;
        height: 1px;
        background: #6DD5FA;
        transition: width 0.3s ease;
    }

    a:hover::after {
        width: 115%;
        /* 线完全展开 */
    }

    a.active {
        color: #6DD5FA;
        font-size: 40px;
        /* 微调放大比例 */
        font-weight: 400;
    }

    a.active::after {
        width: 110%;
        /* 激活状态保持下划线 */
    }

    a::before {
        content: '>';
        margin-right: 12px;
        opacity: 0;
        transition: all 0.3s ease;
        color: #6DD5FA;
    }

    a:hover::before {
        opacity: 1;
        transform: translateX(5px);
    }

}

.main {
    width: 80%;
    height: calc(100vh - 50px - 30px);
    /* 50px顶部栏 + 30px底部留空 */
    background-color: transparent;
    position: relative;
    overflow: hidden;
    top: 0;
    left: 20%;
    z-index: 1;
    display: flex;
}

/* 增加底部留空区域 */
.main::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.2));
}

.router-container {
    flex: 1;
    height: 100%;
    position: relative;
    overflow: hidden;
    /* 增加呼吸感 */
    justify-content: center;
    /* 垂直居中 */
    align-items: center;
    /* 水平居中 */
}

.router-content {
    width: 100%;
    max-width: 1200px;
    /* 限制最大宽度 */
    margin: 0 auto;
    /* 水平居中 */
    height: auto;
    min-height: 80vh;
    /* 最小高度保证垂直居中 */
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow-y: auto;
    padding-bottom: 30px;
    /* 补偿底部留空 */
    background: transparent;
    border-radius: 8px;
    position: relative;
    /* 新增定位上下文 */
}


/* 修复过渡动画的定位问题 */
.transition-group {
    position: relative;
    height: 100%;
}

.transition-wrapper {
    position: absolute;
    /* 改为绝对定位 */
    display: flex;
    justify-content: center;
    align-items: flex-start;
    /* 顶部对齐 */
    height: calc(100% - 50px);
    /* 扣除顶部栏高度 */
    width: 100%;
    box-sizing: border-box;
}

.slide-up-enter-active,
.slide-up-leave-active,
.slide-down-enter-active,
.slide-down-leave-active {
    position: relative;
    /* 保持相对定位 */
    transform: none;
    width: 100%;
    height: 100%;
    /* 新增高度定义 */
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    top: 0;
    left: 0;
}

/* 优化后的动画效果 */
.slide-up-enter-from {
    transform: translateY(100%);
    opacity: 0.5;
}

.slide-up-leave-to {
    transform: translateY(-30%);
    opacity: 0;
}

.slide-down-enter-from {
    transform: translateY(-100%);
    opacity: 0.5;
}

.slide-down-leave-to {
    transform: translateY(30%);
    opacity: 0;
}
</style>